package com.jsyh.maidu.activity.me;

import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jsyh.maidu.R;
import com.jsyh.maidu.activity.BaseActivity;
import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.fragment.StoreDetailFragment;
import com.jsyh.maidu.model.BestNewHotModel;
import com.jsyh.maidu.model.SuppinfoModel;
import com.jsyh.maidu.presenter.SuppInfoPresenter;
import com.jsyh.maidu.views.StoreView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

public class StoreActivity extends BaseActivity implements StoreView,View.OnClickListener{

    ImageView iv_supp;
    TextView tv_suppname,tv_fannum,tv_allgoodnum,tv_cate,tv_shopinfo;
    SuppInfoPresenter presenter;
    RelativeLayout rl_supp;
    DrawerLayout dl_store;
    StoreDetailFragment storedetailfragment;
    TextView tv_title;
    ImageView iv_back;

    String suppid;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store);

        tv_title= (TextView) findViewById(R.id.title);
        iv_back= (ImageView) findViewById(R.id.back);

        iv_supp= (ImageView) findViewById(R.id.iv_store_pic);
        tv_allgoodnum= (TextView) findViewById(R.id.tv_store_allgoodnum);
        tv_fannum= (TextView) findViewById(R.id.tv_story_fannum);
        tv_suppname= (TextView) findViewById(R.id.tv_store_name);
        rl_supp= (RelativeLayout) findViewById(R.id.rl_store_top);
        tv_cate= (TextView) findViewById(R.id.tv_store_cate);
        tv_shopinfo= (TextView) findViewById(R.id.tv_store_info);
        dl_store= (DrawerLayout) findViewById(R.id.dl_store);
        iv_back.setOnClickListener(this);
        findViewById(R.id.ll_store_allgood).setOnClickListener(this);
        dl_store.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        dl_store.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {
                dl_store.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            }

            @Override
            public void onDrawerClosed(View drawerView) {

                dl_store.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });
        storedetailfragment=new StoreDetailFragment();
        FragmentManager fmanager=getSupportFragmentManager();
        FragmentTransaction ftransaction=fmanager.beginTransaction();
        ftransaction.add(R.id.fl_store_detail,storedetailfragment,"storedetailfragment");
        ftransaction.commit();
        tv_cate.setOnClickListener(this);
        tv_shopinfo.setOnClickListener(this);


    }

    @Override
    public void initData() {
        super.initData();
        suppid=getIntent().getStringExtra("suppid");
        presenter=new SuppInfoPresenter(this,this);
        presenter.LaodSuppinfo(suppid);

    }



    @Override
    public void returnSuppInfo(SuppinfoModel model) {

        Picasso.with(mContext).load(ConfigValue.IMG_IP+model.getData().getBg()).into(new Target() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
                rl_supp.setBackground(new BitmapDrawable(getResources(),bitmap));
            }

            @Override
            public void onBitmapFailed(Drawable drawable) {

            }

            @Override
            public void onPrepareLoad(Drawable drawable) {

            }
        });

        Picasso.with(mContext).load(ConfigValue.IMG_IP+model.getData().getSupplierinfo().getLogo()).into(iv_supp);
        tv_fannum.setText(model.getData().getSupplierinfo().getFans());
        tv_suppname.setText(model.getData().getSupplierinfo().getSupplier_name());
        tv_allgoodnum.setText(model.getData().getSupplierinfo().getNumber());
        storedetailfragment.setdetailData(model.getData().getSupplierinfo());
        tv_title.setText(model.getData().getSupplierinfo().getSupplier_name());

    }

    @Override
    public void getShopGoodsList(BestNewHotModel model) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.tv_store_cate:
                Intent classintent=new Intent(this,StoryClassActivity.class);
                classintent.putExtra("suppid",suppid);
                startActivity(classintent);
                break;
            case R.id.tv_store_info:
                dl_store.openDrawer(findViewById(R.id.fl_store_detail));
                break;
            case R.id.back:
                finish();
                break;
            case R.id.ll_store_allgood:
                Intent allGoods = new Intent(this, ShopGoodsListActivity.class);
                allGoods.putExtra("suppid", suppid);
                startActivity(allGoods);
                break;
        }
    }
}
